# src/schemas/sys_menu.py
from pydantic import BaseModel, Field
from typing import Optional
from datetime import datetime


class SysMenuBase(BaseModel):
    parent_id: str = Field("0", description="父节点ID，根节点为 0")
    menu_index: str = Field(..., max_length=64, description="前端路由唯一标识")
    label: str = Field(..., max_length=64, description="菜单名称")
    icon: Optional[str] = Field(None, max_length=64, description="图标组件名")
    path: Optional[str] = Field(None, max_length=128, description="视图文件路径")
    sort_order: int = Field(0, ge=0, description="同级排序，小值在前")
    status: bool = Field(True, description="状态：1-启用 0-禁用")
    deletion_mark: bool = False
    deletion_reason: str | None = None
    deletion_date: datetime | None = None
    deletion_by: str | None = None
    create_date: datetime | None = None
    creator_by: str | None = None
    last_updated_date: datetime | None = None
    last_updated_by: str | None = None


class SysMenuCreate(SysMenuBase):
    api_id: Optional[str] = Field(None, max_length=36, description="API主键，用于关联其他系统")


class SysMenu(SysMenuBase):
    id: str
    api_id: str | None = None

    class Config:
        from_attributes = True   # Pydantic V2 兼容 ORM 模型
